package com.study.common;


import com.study.Util.CommonResponse;
import com.study.common.constants.BaseConstants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description: 全局异常处理
 * @ClassName: BusinessException
 * @Author: hupengming
 * @CreateTime: 2022-09-07 17:54
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public CommonResponse handler(BusinessException exception){
        String code = exception.getCode();
        if(StringUtils.isEmpty(code)){
            code = BaseConstants.EXCEPTION_CODE;
        }
        return CommonResponse.fail(null,code,exception.getMessage());
    }

}
